
var schoolId;
var schoolList;
var techList;

$.fn.pagination.defaults.displayMsg = '';
$(document).ready(function(){
    var DataGrid2  = new DataGridEvent();
    schoolList = $('#SchoolList');
    techList   = $('#TeacherList');
    $('.xh-datagrid-toolbar').parseToolbar();
    schoolList.initDataGrid(baseUrl+'School/getSchForTch');


    xhTool.bindDocKeyDown($('#bt_SchoolList_Search,#bt_TeacherList_Search'));

    //学校列表加载后刷新学生列表
    DataGrid.onLoadSuccess = function(data){
        if(data['rows'].length <= 0) return false;
        var subject   = xhExtra.getValue($('#select_subject'));
        var grade     = xhExtra.getValue($('#select_grade'));
        techParams = {"iUserType": 4,'iSchoolId':null,key:null,subject:subject,grade:grade};
        techList.initDataGrid(baseUrl + 'School/getTchData', {"queryParams": techParams}, DataGrid2)
            // .setSelectThenEnable([], [], 'eu', DataGrid2)
            .datagrid('getPanel').panel('setTitle', '教师列表（全部）');
    };
    //点击学校列表在学生列表显示相应学生
    DataGrid.onClickRow = function(rowIndex, rowData){
        schoolId = rowData.iSchoolId;
        techParams.iSchoolId = schoolId;
        techList.addDataGridParams(techParams)
            .datagrid('getPanel').panel('setTitle', '教师列表（' + rowData.sSchoolName + '）');
        techList.dataGridClear();
    };


    DataGrid2.onSelect = function (rowIndex,rowData) {
        $('#bt_in',parent.document).setButtonEnable('bs');
    };
    DataGrid2.onUnselect = function (rowIndex,rowData) {
        var _rows = techList.datagrid('getSelections');
        if(_rows.length <= 0){
            $('#bt_in',parent.document).setButtonDisable('bs');
        }
    };
    DataGrid2.onSelectAll = function (rowIndex) {
        $('#bt_in',parent.document).setButtonEnable('bs');
    };
    DataGrid2.onUnselectAll = function (rowData) {
        var _rows = techList.datagrid('getSelections');
        if(_rows.length <= 0){
            $('#bt_in',parent.document).setButtonDisable('bs');
        }
    };


    $('#bt_SchoolList_Search').click(function () {
        schParams = {
            key:xhExtra.getValue($('#SchoolList_Search'))
        };
        schoolList.addDataGridParams(schParams);
    });

    $('#bt_TeacherList_Search').click(function () {
        techParams.key       = xhExtra.getValue($('#TeacherList_Search '));
        techParams.subject   = xhExtra.getValue($('#select_subject'));
        techParams.grade     = xhExtra.getValue($('#select_grade'));
        var str = techList.getDataGridSelectedField('sSchoolName');
        if(str==''){
            str = '全部';
        }
        techList.addDataGridParams(techParams)
            .datagrid('getPanel').panel('setTitle', '教师列表（' +str+'）');
    });

});
//选择应用，供子页面调用
//function chooseAppStore(iAppCode){
//    $.post(baseUrl + 'Class/unbindStudent', {iStudentId: iStudentId, iAppCode: iAppCode, iSchoolId: iSchoolId},function(result){
//        window.top.xhTop.showMessage(result);
//    });
//}
// function afterParseToolbar() {
//     $.overtFun.vagueSearch(schoolList, null, $('#SchoolList_Search'));
// }